import amesu from "../model/bot/amesu";
import func from "../model/func";
import { MsgAction, Tpl_auction, template } from "../shared/master/MsgAction";
import { style_default } from "../style/default";
let locaImg = { key: '', dir: '' }
export default async function (data: MsgAction) {
    let d = data.data as Tpl_auction;
    if (!d.nowPrice || !d.item_info || !d.item_info.item_template) {
        amesu.sendText(data.tolocation, `拍卖行现在还没有任何人寄售商品噢,当前在线玩家:${d.playerCont}人,建议人多时拍卖`);
        return;
    }

    let style = new style_default()
    style.setTitle('💰拍卖行')
    style.addLine(`🧙在线玩家:${d.playerCont}人`)
    style.addLine(`🕜️倒计时:${d.downTime}s`)
    style.addLine(`💰当前价格:${d.nowPrice.price}`)
    if(d.item_info.item_data.cont){
        style.addLine(`🔎道具详细:${d.item_info.item_data.name}x${d.item_info.item_data.cont}`)
    }else{
        style.addLine(`🔎道具详细:${d.item_info.item_data.name}⭐️评分${func.BN(d.item_info.item_data.score)}`)
    }
    style.addLine('📄出价历史')
    d.priceList.reverse();
    for (let index = d.priceList.length-1; index < 10;index--) {
        let item = d.priceList[index];
        if (!item) {
            break;
        }
        style.addLine(`${func.getNumIcon(index)}${item.name}:${func.BN(item.price)}💰`)
    }
    style.addLine('↓↓以下为道具预览图↓↓')
    amesu.sendText(data.tolocation, style.end());
    if (locaImg.key != d.id) {
        // 先绘制道具图片
        const module = require(`./${d.item_info.item_template}`);
        let dir = await module.default({template:d.item_info.item_template,data:d.item_info.item_data},true);
        locaImg.key = d.id
        locaImg.dir = dir;
    }
    amesu.sendLocaImage(data.tolocation, locaImg.dir)


}